<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="../../simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css"/>
    <link href="../../css/common.css" rel="stylesheet">
    <!-- Bootstrap core CSS -->
    <link href="../../css/bootstrap.min.css" rel="stylesheet">
    <link href="../../css/default.css" rel="stylesheet">
</head>
<body style="background-color: #FFFFFF;">
<div class="page-container container-fluid" style="margin-top:0;overflow-y:auto;height:100%;">
    <div class="page-bar">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="../main.html">我的工作台</a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li><a href="#">个人信息</a></li>
        </ul>
    </div>

    <ul class="nav nav-tabs">
        <li class="active">
            <a href="#">
                个人信息 </a>
        </li>
    </ul>
    <div class="row">
        <div class="col-md-12">
            <div class="form-horizontal" role="">
                <div class="form-body">
                    <div>
                        <br>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3">用户名：<span class="required">
								</span></label>
                        <div class="col-md-4 col-sm-4">
                            <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名"/>
                            <span class="help-block">
								         请输入用户名
                            </span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3">邮箱：<span class="required">
								</span></label>
                        <div class="col-md-4 col-sm-4">
                            <input type="text" class="form-control" id="email" name="email" placeholder="请输入邮箱"/>
                            <span class="help-block">
								         请输正确的邮箱格式
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3">手机号：<span class="required">
								</span></label>
                        <div class="col-md-4 col-sm-4">
                            <input type="text" class="form-control" id="phone" name="phone" placeholder="请输入手机号"/>
                            <span class="help-block">
								         请输入正确的手机号格式
                            </span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3">性别：<span class="required">
								</span></label>
                        <div class="col-md-4 col-sm-4">
                            <label class="radio-inline">
                                <input type="radio" name="gender" id="boy" value="男" checked="checked">男
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="gender" id="girl" value="女">女
                            </label>
                        </div>
                    </div>

                </div>
                <div class="form-group">
                    <div class="row">
                        <div class="col-md-offset-3 col-md-9 col-sm-offset-3 col-sm-9">
                            <button class="btn blue" id="btn-update">修改</button>
                            <button type="reset" class="btn default "><i class="icon icon-refresh"></i>重置信息</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script src="../../js/jquery-2.0.2.js"></script>
<script src="../../js/jquery.cookie-1.4.1.js"></script>
<script>
    $(function () {
        let uid = $.cookie("uid");
        $.ajax({
            type: "get",
            url: "http://localhost/user/me/" + uid,
            success: function (result) {
                if (result.code != 0) {
                    alert(result.msg);
                } else {
                    let user = result.data;
                    $("#username").val(user.userName);
                    $("#phone").val(user.phone);
                    $("#email").val(user.email);
                    if ("男" === user.gender) {
                        $("#boy").attr("checked", true);
                        $("#girl").attr("checked", false);
                    } else {
                        $("#girl").attr("checked", true);
                        $("#boy").attr("checked", false);
                    }
                }
            }
        });
    });
</script>
<script>

    $("#btn-update").click(function () {
        var username = $("#username").val();
        var phone = $("#phone").val();
        var email = $("#email").val();
        var id = $.cookie("uid");
        $.ajax({
            type: "post",
            url: "http://jack/user/update",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                "id": id,
                "userName": username,
                "phone": phone,
                "email": email
            }),
            success: function (result) {
                console.log(result.code);
            },
            error: function (e) {
                console.log(e);
            }
        });

    });
</script>
</html>
